
//  SISSJsonRequestNetworkingManager+Resources.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/30.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSJsonRequestNetworkingManager+Resources.h"

@implementation SISSJsonRequestNetworkingManager (Resources)

// 2.2.1 已委托房源
- (void)requestEntrustHouseResourceWithParameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSHouseResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENTRUS_HOUSE_RESOURCE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.2.1 已委托房源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.2.2 已委托客源
- (void)requestEntrustPassengerResourceWithParameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSPassengerResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENTRUST_PASSENGER_RESOURCE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.2.2 已委托客源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.1 筛选房源、找房源的请求
- (void)requestFilterSearchHouseResourceWithPageNo:(NSInteger)pageNo parameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSInteger pageSize = 20; // 一页数量
    NSDictionary *parameter = @{
                                @"spId":[SISSUserAccount shared].spId,
                                @"saId":[SISSUserAccount shared].saId,
                                @"soId":[SISSUserAccount shared].soId,
                                @"sobId":[SISSUserAccount shared].sobId,
                                @"pageSize":@(pageSize),
                                @"pageNo":@(pageNo),
                                };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameter];
    [params addEntriesFromDictionary:parameters];
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_HOUSE_RESOURCE parameters:params success:^(id responseObject) {
        NSLog(@"2.4.1 筛选房源、找房源的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.2 筛选客源、找客源的请求
- (void)requestFilterSearchPassengerResourceWithPageNo:(NSInteger)pageNo parameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSInteger pageSize = 20; // 一页数量
    NSDictionary *parameter = @{
                                @"spId":[SISSUserAccount shared].spId,
                                @"saId":[SISSUserAccount shared].saId,
                                @"soId":[SISSUserAccount shared].soId,
                                @"sobId":[SISSUserAccount shared].sobId,
                                @"pageSize":@(pageSize),
                                @"pageNo":@(pageNo),
                                };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameter];
    [params addEntriesFromDictionary:parameters];
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_PASSENGER_RESOURCE parameters:params success:^(id responseObject) {
        NSLog(@"2.4.2 筛选客源、找客源的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];

}

// 2.4.3 筛选房源合作、找房源合作的请求
- (void)requestFilterHouseResourceCooperationWithParameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_HOUSE_COOPERATION parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.3 筛选房源合作、找房源合作的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }

        
    } failure:^(NSError *error) {
        NSLog(@"+++++%@",error);
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.4 筛选客源合作、找客源合作的请求
- (void)requestFilterPassengerResourceCooperationWithParameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_PASSENGER_COOPERATION parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.4 筛选客源合作、找客源合作的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.9.1 推荐房源
- (void)requestInsetRecommendHouseWithPassengerId:(NSString *)passengerId houseArr:(NSArray<SISSHouseResourceModel *> *)houserArr success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSInteger i = 0; i < houserArr.count; i++) {
        
        SISSHouseResourceModel *model = houserArr[i];
        
        NSString *houseId = model.houseresType == 1 ? model.ID : @"-1";
        NSString *ahroId = model.houseresType == 1 ? @"-1" : model.ID;
        NSInteger isMain = model.isSelected ? 1 : 0;
        
        NSDictionary *dict = @{
                               @"id":houseId,
                               @"spId":[SISSUserAccount shared].spId,
                               @"ahroId":ahroId,
                               @"abdId":passengerId,
                               @"isMain":@(isMain)
                               };
        [arrM addObject:dict];
    }
    
    NSDictionary *parameters = @{@"demand":arrM.copy};
    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_RECOMMEND_HOUSE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.9.1 推荐房源的请求: responseObject-->%@",responseObject);
        
        
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.9.2 推荐客源
- (void)requestInsetRecommendPassengerWithHouseId:(NSString *)houseId passengerArr:(NSArray<SISSPassengerResourceModel *> *)passengerArr success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSInteger i = 0; i < passengerArr.count; i++) {
        
        SISSPassengerResourceModel *model = passengerArr[i];
        
        NSString *passengerId = model.demandType == 1 ? model.ID : @"-1";
        NSString *abdoId = model.demandType == 1 ? @"-1" : model.ID;
        NSInteger isMain = model.isSelected ? 1 : 0;
        
        NSDictionary *dict = @{
                               @"id":passengerId,
                               @"spId":[SISSUserAccount shared].spId,
                               @"abdoId":abdoId,
                               @"ahrId":houseId,
                               @"state":@0,
                               @"isMain":@(isMain)
                               };
        [arrM addObject:dict];
    }
    
    
    NSDictionary *parameters = @{@"demand":arrM.copy};
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_RECOMMEND_PASSENGER parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.9.2 推荐客源的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

#pragma mark - 2.0
// 2.2.3 获取已委托出租信息
- (void)requestEntrustRentOutResourceWithParameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSRentOutModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENTRUS_RENTOUT_RESOURCE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.2.3 获取已委托出租信息: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *rentOutArr = [NSArray yy_modelArrayWithClass:[SISSRentOutModel class] json:dataArr];
        if (successBlock) {
            successBlock(rentOutArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.2.4 获取已委托租客信息
- (void)requestEntrustTenantResourceWithParameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSTenantModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENTRUST_TENANT_RESOURCE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.2.4 获取已委托租客信息: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *tenantArr = [NSArray yy_modelArrayWithClass:[SISSTenantModel class] json:dataArr];
        if (successBlock) {
            successBlock(tenantArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 2.4.5 筛选出租、找出租
- (void)requestFilterRentOutResourceCooperationWithParameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_RENTOUT_RESOURCE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.5 筛选出租、找出租: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.6 筛选租客、找租客
- (void)requestFilterTenantResourceCooperationWithParameters:(NSDictionary *)parameters success:(void (^)(SISSBasePagingModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_TENANT_RESOURCE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.6 筛选租客、找租客: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSBasePagingModel *baseModel = [SISSBasePagingModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(baseModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.7 筛选新房、找新房
- (void)requestFilterNewHouseResourceWithParameters:(NSDictionary *)parameters success:(void (^)(SISSNewHouseListModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;
    [kJsonRequestNetworkingManager POSTWithURLString:URL_FILTER_NEW_HOUSE_RESOURCE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.7 筛选新房、找新房: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSNewHouseListModel *model = [SISSNewHouseListModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.4.7.1 获取新房楼盘详情 GET请求
- (void)requestNewHouseBuildingDetailResourceWithBuidName:(NSString *)buildName success:(void (^)(SISSBuildingProjectModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name": buildName};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_GET_NEW_HOUSE_BUILD_HOME parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.4.7.1 获取新房楼盘详情: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSBuildingProjectModel *model = [SISSBuildingProjectModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

@end
